//
//  GLViewController.m
//  GLFormKit
//
//  Created by zhiyong0906 on 12/06/2017.
//  Copyright (c) 2017 zhiyong0906. All rights reserved.
//

#import "GLViewController.h"
#import <GLFormKit/GLFormKit-umbrella.h>
#import "GLCustomCellHelper.h"
@interface GLViewController ()
@property(nonatomic,strong)NSArray* datas;
@end

@implementation GLViewController


- (void)viewDidLoad {
    
    [GLCustomCellHelper registerHelper];
    
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.separatorInset = UIEdgeInsetsZero;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark- UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datas.count;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSDictionary* cellDict = [self.datas objectAtIndex:indexPath.row];
    
    NSString* cellIdentifier = [cellDict valueForKey:@"identifier"];;
    
    GLCustomCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        NSArray* controlkeys = [cellDict valueForKey:@"contolkeys"];
        cell = [[GLCustomCell alloc]initWithCustom:controlkeys reuseIdentifier:cellIdentifier];
    }
    NSDictionary* value = [cellDict valueForKey:@"value"];
    [cell setComponentValuesForKeys:value];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary* dict = [self.datas objectAtIndex:indexPath.row];
    Class aclass = NSClassFromString(dict[@"controller"]);
    
    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell.contentView hideBadge];
    
    [self.navigationController pushViewController:[aclass new] animated:YES];
}

#pragma mark- getter and setter
-(NSArray*)datas{
    //GLButtonViewController
    return @[
        
             @{
                 @"value":@{GLCustomCellText:@"角标BADGE",
                            GLCustomCellIcon:@"icon",
                            GLCustomCellCatpionText:@"应用角标，提示",
                            @"GLCustomCellBadge.bindKeyPath":@"com",
                            },
                 @"identifier":@"cell2315423",
                 @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellBadge,GLCustomCellArrow],
                 @"controller":@"GLBadgeViewController",
                 },

             @{
                 @"identifier":@"cell53323",
                 @"value":@{GLCustomCellText:@"设置界面CELL",
                            GLCustomCellIcon:@"icon",
                            GLCustomCellCatpionText:@"自定义CELL，高可复用",
                            GLCustomCellBadge:@"NEW",
                            },
                 @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellBadge,GLCustomCellArrow],
                 @"controller":@"GLSettingViewController",
                 },
             //      @{
             //        @"value":@{GLCustomCellText:@"scaleScrolview",
             //                   GLCustomCellIcon:@"icon",
             //                   GLCustomCellCatpionText:@"滑动时放大缩小"
             //                   },
             //        @"identifier":@"celldhgh5423",
             //        @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
             //        @"controller":@"GLScalSViewController",
             //        },
             @{
                 @"value":@{GLCustomCellText:@"表单",
                            GLCustomCellIcon:@"icon",
                            GLCustomCellCatpionText:@"自定义表单"
                            },
                 @"identifier":@"celldhgh5423",
                 @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                 @"controller":@"GLKTableViewController",
                 
                 },
             @{
                 
                 @"value":@{GLCustomCellText:@"数据选择器",
                            GLCustomCellIcon:@"icon",
                            GLCustomCellCatpionText:@"自定义"
                            },
                 @"identifier":@"celldhghsshdsffdff5423",
                 @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                 @"controller":@"GLPickerViewController",
                 },
             @{
                 
                 @"value":@{GLCustomCellText:@"GLCustomCell",
                            GLCustomCellIcon:@"icon",
                            GLCustomCellCatpionText:@"自定义"
                            },
                 @"identifier":@"celldhghssdafasdhdsffdff5423",
                 @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                 @"controller":@"GLTableViewController",
                 },
             ];
}
@end
